package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class SupplierController {


    @Autowired
    SupplierService supplierService;



    /**
     * 请求URL：http://localhost:8080/supplier/list
     * 请求参数：Integer page（当前页数）, Integer rows（每页显示的记录数）, String supplierName
     * 请求方式：POST
     * 返回值类型： JSON
     * 返回值：Map<String,Object>
     * Response Example Value：请求URL：http://localhost:8080/supplier/list
     * 请求参数：Integer page（当前页数）, Integer rows（每页显示的记录数）, String supplierName
     * 请求方式：POST
     * 返回值类型： JSON
     * 返回值：Map<String,Object>
     * Response Example Value：
     */
    @PostMapping("/supplier/list")
    @ResponseBody
    public Map<String, Object> listSupplier(Integer page, Integer rows, String supplierName ){

        return supplierService.list( page, rows, supplierName) ;

    }

    /**
     Request URL: http://localhost:8080/supplier/save
     Request Method: POST
     Status Code: 404
     添加供应商
     */

    @PostMapping("supplier/save")
    public ServiceVO addSupplier(Supplier supplier, @RequestParam(value = "supplierId",required = false) Integer supplierId){

        supplierService.addSupplier(supplier,supplierId);

        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }


    /**
     * 请求URL：http://localhost:8080/supplier/delete
     * 请求参数：String  ids
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：ServiceVO
     */
    @PostMapping("/supplier/delete")
    public ServiceVO deleteSupplier(String ids){

        supplierService.deleteSupplier(ids);

        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);



    }

}
